from config import MultiNodeConfig

class Config:
    # 动态获取 Redis 主机地址
    def __init__(self, role="worker"):
        redis_host = MultiNodeConfig.get_redis_host(role=role)
        self.broker_url = f'redis://{redis_host}:{MultiNodeConfig.REDIS_PORT}/{MultiNodeConfig.REDIS_DB}'
        self.result_backend = f'redis://{redis_host}:{MultiNodeConfig.REDIS_PORT}/{MultiNodeConfig.REDIS_DB}'

    task_serializer = 'json'
    result_serializer = 'json'
    accept_content = ['json']
    timezone = 'Asia/Shanghai'
    enable_utc = True
    result_expires = 3600
    task_track_started = True
    task_time_limit = 3600
    task_soft_time_limit = 300
    worker_max_tasks_per_child = 100
    worker_prefetch_multiplier = 1
    task_acks_late = True
    task_default_queue = 'default'
    task_queues = {
        'default': {
            'exchange': 'default',
            'exchange_type': 'direct',
            'binding_key': 'default'
        },
        'high_priority': {
            'exchange': 'high_priority',
            'exchange_type': 'direct',
            'binding_key': 'high_priority'
        }
    }
    task_routes = {
        'tasks.create_vm_async': {'queue': 'high_priority'},
        'tasks.migrate_vm_async': {'queue': 'high_priority'},
    }